function toast(msg) {
	let snack = document.getElementById('snack-bar');
	if (snack) {
		let data = {message: msg};
		snack.MaterialSnackbar.showSnackbar(data);
	} else {
		alert(msg);
	}
}

function request(method, url) {
	let request = new XMLHttpRequest();
	request.open(method, url);
	return request;
}

function get(url) {
	return new Promise(resolve => {
		let req = request('GET', url);
		req.onreadystatechange = function () {
			if (req.readyState === 4) {
				resolve(req.response);
			}
		};
		req.send();
	});
}

function post(url, data) {
	return new Promise(resolve => {
		let req = request('POST', url);
		req.onreadystatechange = function () {
			if (req.readyState === 4) {
				resolve(req.response);
			}
		};
		req.send(data);
	});
}
